package com.itjeffrey.autocode.runner;

import com.itjeffrey.autocode.bo.RandomWordBO;
import com.itjeffrey.autocode.service.AsyncService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @From: Jeffrey
 * @Date: 2021/6/24
 */
@Getter
@Slf4j
@Component
@Order(value = 2)
public class RandomWordInitRunner implements CommandLineRunner {

    private RandomWordBO randomWordBO;

    @Autowired
    private AsyncService asyncService;

    /**
     * init several random words after starting this project.
     */
    @Override
    public void run(String... args) throws Exception {
        log.debug("starting random words generating...");
        asyncService.generateWord();
    }

    public void setRandomWordBO(RandomWordBO randomWordBO){
        this.randomWordBO = randomWordBO;
        log.debug("random word size: {}", this.randomWordBO.getRandomWords().size());
    }

}
